package com.igeekhome.egobuycontentservice.service.impl;

import com.igeekhome.egobuy.content.pojo.TbContent;
import com.igeekhome.egobuycontentservice.mapper.ContentMapper;
import com.igeekhome.egobuycontentservice.service.TbContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

/**
 * @Author : FMH
 * @Date : 2020/3/3 18:50
 * @Description :
 * @Modify By : 86159
 * @Version :
 */
@Service
public class TbContentServiceImpl implements TbContentService {

    @Autowired
    private ContentMapper contentMapper;

    @Override
    public TbContent queryById(Long categoryId) {
        return null;
    }

    @Override
    public List<TbContent> queryAllByLimit(int offset, int limit) {
        return contentMapper.selectAll();
    }

    @Override
    public List<TbContent> queryAllByCategoryId(Long categoryId) {
        Example example = new Example(TbContent.class);
        example.createCriteria().andEqualTo("categoryId",categoryId);
        List<TbContent> tbContents = contentMapper.selectByExample(example);
        return tbContents;
    }


    @Override
    public TbContent insert(TbContent tbContent) {
        tbContent.setCreated(new Date());
        tbContent.setUpdated(new Date());
        contentMapper.insert(tbContent);
        return tbContent;
    }

    @Override
    public TbContent update(TbContent tbContent) {
        tbContent.setUpdated(new Date());
        System.out.println(tbContent.toString());
        contentMapper.updateByPrimaryKeySelective(tbContent);
        return tbContent;
    }

    @Override
    public boolean deleteById(Long id) {
        contentMapper.deleteByPrimaryKey(id);
        return false;
    }
}
